home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / MBLIB10.ZIP;1 / CPPEXAMP.ZIP / TEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-29  |  1.2 KB  |  65 lines

  1. #include    "iostream.h"
  2. #include    "string.h"
  3.  
  4. /*********************************************************************
  5.  
  6.     Laat een class member refereren aan een globale variabele, zodat
  7.     deze 'verborgen' blijft voor de gebruiker. De globale variabele
  8.     wordt door de library bijgehouden, de gebruiker moet deze echter
  9.     via de de C++ shell benaderen.
  10.  
  11.  *********************************************************************/
  12.  
  13. extern "C"
  14. {
  15. int   fooint;
  16. char  foostring[11];
  17. }
  18.  
  19. class foo1
  20. {
  21.     public:
  22.  
  23.         int        &intReference;
  24.         char *    stringReference;
  25.  
  26.                 foo1 (void) :    intReference (fooint),
  27.                                 stringReference (foostring) {} ;
  28.         virtual    ~foo1 (void) {} ;
  29.  
  30.         void    foo (void) { cout << "Testing foo1" << endl; } ;
  31. };
  32.  
  33. class foo2
  34. {
  35.     public:
  36.  
  37.         int        &intReference;
  38.         char *    stringReference;
  39.  
  40.                 foo2 (void) :    intReference (fooint),
  41.                                 stringReference (foostring) {} ;
  42.         virtual    ~foo2 (void) {} ;
  43.  
  44.         void    foo (void) { cout << "Testing foo2" << endl; } ;
  45. };
  46.  
  47. void main (void)
  48.  
  49. {
  50.     foo1    *test = new foo1;
  51.  
  52.     fooint = 1;
  53.     strcpy (foostring, "test");
  54.  
  55.     if (test)
  56.     {
  57.         cout << "Testing: " << test->intReference << ", "
  58.              << test->stringReference << ".\n";
  59.  
  60.         test->foo ();
  61.  
  62.         delete test;
  63.     }
  64. }
  65.